package com.hgshop.yudongyang.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.dubbo.config.annotation.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hgshop.yudongyang.dao.SpecMapper;
import com.hgshop.yudongyang.domain.Spec;
import com.hgshop.yudongyang.domain.SpecOption;
import com.hgshop.yudongyang.service.SpecService;
@Service
public class SpecServiceImpl implements SpecService{

	@Resource
	SpecMapper specMapper;
	
	@Override
	public PageInfo<Spec> specList(Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		//System.out.println("123456----------");
		return new PageInfo<Spec>(specMapper.specList());
	}
	@Override
	public int dels(Integer[] ids) {
		// TODO Auto-generated method stub
		return specMapper.specdels(ids);
	}
	@Override
	public int addSpec(Spec spec) {
		specMapper.addSpec(spec);
		List<SpecOption> optionList = spec.getOptionList();
		specMapper.addSpecOntion(spec.getId(),optionList);
		return 1;
	}
	@Override
	public int delSpec(Integer id) {
		// TODO Auto-generated method stub
		//删除规格选项表
		specMapper.delSpecOption(id);
		//删除规格名称
		specMapper.delSpec(id);
		return 1;
	}
	/**
	 * 去修改
	 */
	@Override
	public Spec getOne(Integer id) {
		// TODO Auto-generated method stub
		return specMapper.getOne(id);
	}
	@Override
	public void update(Spec spec) {
		//修改主表
		specMapper.updateSpec(spec);
		//删除spec_option
		specMapper.deleteOption(spec.getId());
		//添加
		specMapper.addSpecOntion(spec.getId(), spec.getOptionList());
	}
	@Override
	public List<SpecOption> findSpecOptionById(Integer id) {
		// TODO Auto-generated method stub
		return specMapper.findSpecOptionById(id);
	}
	@Override
	public List<Spec> findSpecBySkuId(Integer id) {
		// TODO Auto-generated method stub
		return specMapper.findSpecBySkuId(id);
	}
}
